package com.mustafaiev.tair.cts.authentication;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import com.mustafaiev.tair.constant.Attributes;

public class AuthenticationFailureHandler extends
		SimpleUrlAuthenticationFailureHandler {

	@Override
	public void onAuthenticationFailure(final HttpServletRequest request,
			final HttpServletResponse response,
			final AuthenticationException exception) throws IOException,
			ServletException {
		request.setAttribute(Attributes.ERROR_MESSAGE, exception.getMessage());
		super.setUseForward(true);
		super.setDefaultFailureUrl("/login");
		super.onAuthenticationFailure(request, response, exception);
	}

}
